package Listener;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;

import Util.MODE;

public class ClearListener implements Listener {

	private Canvas canvas;
	private String[] mode;
	
	public ClearListener(String[] mode, Canvas canvas){
		this.canvas = canvas;
		this.mode = mode;
	}
	
	@Override
	public void handleEvent(Event event) {
		if(mode[MODE.MODE].equals(MODE.CLEAR)){
			int size = event.widget.getDisplay().getShells().length;
		
			
			switch(event.type){
			case SWT.Selection:
				if(size > 1){
					for(int i = 0; i < size; i++ ){
						for(int j = 0; j < event.widget.getDisplay().getShells()[i].getChildren().length; j++){
							if(event.widget.getDisplay().getShells()[i].getChildren()[j] instanceof Canvas){
								canvas = (Canvas)(event.widget.getDisplay().getShells()[i]).getChildren()[j];
								canvas.redraw();
							}
						}
					}
				}
				else
					canvas.redraw();
			}
		
		}
	}
	
}
